home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / smixc130.zip / XMS.C < prev    next >
C/C++ Source or Header  |  1997-06-06  |  3KB  |  142 lines

  1. /*      SMIXC is Copyright 1995 by Ethan Brodsky.  All rights reserved      */
  2.  
  3. /* ██ XMS.C ███████████████████████████████████████████████████████████████ */
  4.  
  5.   int xms_installed(void);
  6.   void xms_init(void);
  7.  
  8.   unsigned int xms_getversion(void);
  9.   unsigned int xms_getfreemem(void);
  10.  
  11.   int xms_allocate(int far *handle, unsigned int size);
  12.   int xms_reallocate(int handle, unsigned int newsize);
  13.   int xms_free(int far *handle);
  14.  
  15.   typedef struct
  16.     {
  17.       unsigned long length;         /* Length must be a multiple of two */
  18.       unsigned int  sourcehandle;
  19.       unsigned long sourceoffset;
  20.       unsigned int  desthandle;
  21.       unsigned long destoffset;
  22.     } MOVEPARAMS;
  23.  
  24.   int xms_move(MOVEPARAMS far *params);
  25.  
  26. /* ████████████████████████████████████████████████████████████████████████ */
  27.  
  28. #include <mem.h>
  29.  
  30. #pragma option -w- // Prevent "Function should return a value" warning
  31.  
  32. /* Disable stack overflow checking.  The code for detecting stack overflows */
  33. /* assumes that it is working with the program's stack.  SMIX has a number  */
  34. /* of routines called from interrupts, when the system may be using another */
  35. /* stack.  For this reason, the overflow checking will detect an overflow   */
  36. /* when there is none. Disabling checking for SMIX modules eliminates this. */
  37. #pragma option -N-
  38.  
  39. static void far *xms_driver = NULL;                /* Pointer to XMS driver */
  40.  
  41. int xms_installed(void)
  42.   {
  43.     asm {
  44.       mov  ax, 0x4300
  45.       int  0x2F
  46.     }
  47.     if (_AL == 0x80)
  48.       return 1;
  49.     else
  50.       return 0;
  51.   }
  52.  
  53. void xms_init()
  54.   {
  55.     asm {
  56.       mov  ax, 0x4310
  57.       int  0x2F
  58.       mov  word ptr [xms_driver], bx
  59.       mov  word ptr [xms_driver+2], es
  60.     }
  61.   }
  62.  
  63. /* ──────────────────────────────────────────────────────────────────────── */
  64.  
  65. unsigned int xms_getversion()
  66.   {
  67.     asm {
  68.       mov  ah, 0x00
  69.       call [xms_driver]
  70.     }
  71.   }
  72.  
  73. /* ──────────────────────────────────────────────────────────────────────── */
  74.  
  75. unsigned int xms_getfreemem()
  76.   {
  77.     asm {
  78.       mov  ah, 0x08
  79.       call [xms_driver]
  80.       mov  ax, dx
  81.     }
  82.   }
  83.  
  84. /* ════════════════════════════════════════════════════════════════════════ */
  85.  
  86. int xms_allocate(int far *handle, unsigned int size)
  87.   {
  88.     asm {
  89.       mov  ah, 0x09
  90.       mov  dx, size
  91.       call [xms_driver]
  92.       les  di, [handle]
  93.       mov  es:[di], dx
  94.     }
  95.   }
  96.  
  97. /* ──────────────────────────────────────────────────────────────────────── */
  98.  
  99. int xms_reallocate(int handle, unsigned int newsize)
  100.   {
  101.     asm {
  102.       mov  ah, 0x0F
  103.       mov  bx, newsize
  104.       mov  dx, handle
  105.       call [xms_driver]
  106.     }
  107.   }
  108.  
  109. /* ──────────────────────────────────────────────────────────────────────── */
  110.  
  111. int xms_free(int far *handle)
  112.   {
  113.     asm {
  114.       mov  ah, 0x0A
  115.       les  di, [handle]
  116.       mov  dx, es:[di]
  117.       call [xms_driver]
  118.       mov  word ptr es:[di], 0
  119.     }
  120.   }
  121.  
  122. /* ════════════════════════════════════════════════════════════════════════ */
  123.  
  124. int xms_move(MOVEPARAMS far *params)
  125.   {
  126.     asm {
  127.       push ds
  128.       push es
  129.       mov  ax, ds
  130.       mov  es, ax
  131.       mov  ah, 0x0B
  132.       lds  si, [params]
  133.       call es:[xms_driver]        // necessary to work in huge model
  134.       pop  es
  135.       pop  ds
  136.     }
  137.   }
  138.  
  139. /*██████████████████████████████████████████████████████████████████████████*/
  140.  
  141. #pragma option -w  // Re-enable "function should return a value" warning
  142.